package com.fafa.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//将拦截器通过注解交给容器管理
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    /*添加Controller映射*/
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        /*自定义映射路径*/
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        //映射过来 表面上是显示main.html  实际内容是dashboard里面的
        registry.addViewController("/main.html").setViewName("dashboard");
    }

    //自定义国际化
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*
        addPathPatterns 是需要拦截的路径 /**就是全部
        excludePathPatterns 就是不被拦截的资源

         */
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**").excludePathPatterns("/login.html",
                "/","/user/login","/css/*","/img/*","/js/*");
    }
}
